from apscheduler.schedulers.background import BackgroundScheduler

from app import settings
from app.task import tick, order, return_goods, inventory
from libs.chalk import Chalk


def init_task():
    if settings.EXECUTE_SCHEDULED_TASKS:
        scheduler = BackgroundScheduler()
        scheduler.add_job(tick.echo, 'interval', seconds=3600)  # 1小时
        scheduler.add_job(order.recover_pay_failed_order, 'interval', seconds=3600)  # 1小时
        scheduler.add_job(order.clean_retained_order, 'interval', seconds=86400)
        scheduler.add_job(return_goods.app_goods_coupon, 'cron', hour='2')
        scheduler.add_job(inventory.notify_managers_to_take_inventory, 'cron', hour='9', minute='0')
        scheduler.start()
    else:
        Chalk().red('定时任务未启动').echo()
